package api_servers
{
	import flash.net.URLVariables;
	
	public dynamic class api_myserver extends api_server {
	    protected var _session_key: String = '';
		public static const MYERROR: String = 'MYERROR';
	    
		public function api_myserver(a_sroot: Object, api_url:String, a_api_id: String, a_secret: String) {
			super(a_sroot, api_url, '', a_api_id, a_secret, 0);
		}
		
		override protected function srHelper( arr:Array): URLVariables {// sendRequestHelper
			arr.push( {pn: "app_id", pv: app_id } );
			if (_session_key) arr.push( {pn: "session_key", pv: _session_key } );
			arr.sortOn('pn');
			
			var url_vars:URLVariables = new URLVariables();
			for( var i:uint = 0; i < arr.length; i++ ) {
				url_vars[ (arr[i].pn) ] = arr[ i ].pv;
			}
			url_vars["sig"] = makeSig( arr );
			return url_vars;
		}
		
	    override protected function prepareData(a_queryID:String, a_data:*):* {
	    	if (a_data.errors) {
	    		sroot.dispatchEvent(new GDataEvent(MYERROR, {
	    			queryID		: a_queryID,
	    			error_code	: a_queryID,
	    			error_msg	: (a_data.errors as Array).join('\n')
	    		}));
	    	}
	    	return super.prepareData(a_queryID, a_data);
	    }
	    
	    override public function getFriends(uid: String, handler_:*, queryID:String=''): void {
			var params: Array = [
				{pn:'querycount', pv:1},
				{pn:'query1', pv:'sokoban;getFriends;' + uid}
			];
			jsrHelper(params, handler_, queryID);
	    }

	}	
}